package pub.wkq.common.exception;

import pub.wkq.common.result.ResponseStatusEnum;

/**
 * 自定义异常
 * 目的： 统一的处理异常信息
 * 便于解耦、拦截器、service、controller等异常信息的结构
 *          不会被 service
 */
public class CustomException extends RuntimeException {
    private ResponseStatusEnum responseStatusEnum;

    public CustomException(ResponseStatusEnum responseStatusEnum) {
        super("异常状态码为：" + responseStatusEnum.status() + "；具体异常信息为：" + responseStatusEnum.msg());
        this.responseStatusEnum = responseStatusEnum;
    }

    public ResponseStatusEnum getResponseStatusEnum() {
        return responseStatusEnum;
    }

    public void setResponseStatusEnum(ResponseStatusEnum responseStatusEnum) {
        this.responseStatusEnum = responseStatusEnum;
    }

//    /**
//     * 重写 fillInStackTrace 方法，不填充栈信息提高性能
//     */
//    @Override
//    public synchronized Throwable fillInStackTrace() {
//        return this;
//    }

    /**
     * 静态方法：用于抛出异常
     */
    public static void thr(ResponseStatusEnum responseStatusEnum) {
        throw new CustomException(responseStatusEnum);
    }
}
